package com.geostar.constructionland.index.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.geostar.constructionland.index.util.FormatUtils;
import com.geostar.constructionland.index.entity.InxStorageAcotEntity;
import com.geostar.constructionland.index.entity.model.IndexStorageFreezeModel;
import com.geostar.constructionland.index.entity.model.InsertInxStogAcotModel;
import com.geostar.constructionland.index.entity.model.InxStogAcotModel;
import com.geostar.constructionland.index.service.InxStorageAcotService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.*;

/***
 * 入库台账
 * @author yell
 */
@RestController
@RequestMapping("/inxstorageacot")
@Api(tags = "入库台账相关接口")
public class InxStorageAcotController {
    @Resource
    InxStorageAcotService inxStorageAcotService;

    @ApiOperation(value = "获取入库台账信息列表",notes = "获取入库台账信息列表，必须设置分页参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pagenum",value = "页码测试",required = true),
            @ApiImplicitParam(name = "pagesize",value = "页数测试",required = true),
            @ApiImplicitParam(name = "distCodeProvince",value = "省区划代码"),
            @ApiImplicitParam(name = "distCodeCity",value = "市区划代码"),
            @ApiImplicitParam(name = "distCodeCountry",value = "县区划代码"),
            @ApiImplicitParam(name = "indexType",value = "指标业务类型"),
            @ApiImplicitParam(name = "indexYear",value = "指标年度"),
            @ApiImplicitParam(name = "sortOrder",value = "排序类型 "),
            @ApiImplicitParam(name = "sortName",value = "排序字段 "),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public IPage<InxStorageAcotEntity> queryInxStorageList(@Valid InxStogAcotModel inxStogAcotModel){
        return inxStorageAcotService.queryInxStogAcotList(inxStogAcotModel);
    }

    @ApiOperation(value = "获取入库台账信息列表集合不分页",notes = "获取入库台账信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pagenum",value = "页码测试",required = true),
            @ApiImplicitParam(name = "pagesize",value = "页数测试",required = true),
            @ApiImplicitParam(name = "distCodeProvince",value = "省区划代码"),
            @ApiImplicitParam(name = "distCodeCity",value = "市区划代码"),
            @ApiImplicitParam(name = "distCodeCountry",value = "县区划代码"),
            @ApiImplicitParam(name = "indexType",value = "指标业务类型"),
            @ApiImplicitParam(name = "indexYear",value = "指标年度"),
    })
    @PostMapping(value = "/listAll")
    @ResponseBody
    public List<InxStorageAcotEntity> queryInxStorageAllList(@Valid InxStogAcotModel inxStogAcotModel){
        return inxStorageAcotService.queryInxStorageAllList(inxStogAcotModel);
    }

    @ApiOperation(value = "添加或修改入库台账信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "入库id"),
            @ApiImplicitParam(name = "distCode",value = "行政区划代码"),
            @ApiImplicitParam(name = "distName",value = "行政区划名称"),
            @ApiImplicitParam(name = "indexYear",value = "指标年份",required = true,dataType = "int" , defaultValue="0"),
            @ApiImplicitParam(name = "indexName",value = "指标名称",required = true),
            @ApiImplicitParam(name = "indexType",value = "指标类型",required = true),
            @ApiImplicitParam(name = "buildLandAdd",value = "新增建设用地(BigDecimal)",required = true),
            @ApiImplicitParam(name = "agclLand",value = "农用地(BigDecimal)"),
            @ApiImplicitParam(name = "farmland",value = "耕地(BigDecimal)"),
            @ApiImplicitParam(name = "indexStatus",value = "指标状态",required = true),
            @ApiImplicitParam(name = "operatorId",value = "操作人ID",required = true),
            @ApiImplicitParam(name = "remark",value = "备注"),
            @ApiImplicitParam(name = "effectiveTime",value = "生效时间",required = true),
            @ApiImplicitParam(name = "nonEffectiveTime",value = "失效时间"),
            @ApiImplicitParam(name = "distCodeProvince",value = "省级行政区划代码"),
            @ApiImplicitParam(name = "distCodeCity",value = "市级行政区划代码"),
            @ApiImplicitParam(name = "distCodeCountry",value = "县级行政区划代码"),
            @ApiImplicitParam(name = "specialItemType",value = "专项类型"),
            @ApiImplicitParam(name = "overallType",value = "统筹类型",required = true),
    })
    @PostMapping(value = "/insertOrUpdate")
    @ResponseBody
    public String insertOrUpdateInxStorageAcot(@Valid InsertInxStogAcotModel insertInxStogAcotModel){
        inxStorageAcotService.addOrUpdateInxStogAcout(insertInxStogAcotModel);
        return "Message:success";
    }



    @ApiOperation(value = "根据入库id获取入库台账信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "入库id",required = true),
    })
    @PostMapping(value = "/query/{id}")
    @ResponseBody
    public InxStorageAcotEntity queryInxStorageAcotById(@PathVariable String id){
        return inxStorageAcotService.queryInxStorageAcot(id);

    }

    @ApiOperation(value = "根据入库id集合删除入库台账信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "入库id集合",required = true),
    })
    @PostMapping(value = "/delete")
    @ResponseBody
    public String deleteByInxStorageAcotByIds(@RequestParam(name = "ids") String ids){
        inxStorageAcotService.delInxStoragAcoutByIds(FormatUtils.getStringByList(ids));
        return "Message:success";
    }

    @ApiOperation(value = "指标冻结")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "operatorId",value = " 操作人id zbbl.czrid",required = true),
            @ApiImplicitParam(name = "projectName",value = " 项目名称 zbbl.xmmc",required = true),
            @ApiImplicitParam(name = "distCodeProvince",value = "省级行政区划代码 zbbl.xzqhdmProvince"),
            @ApiImplicitParam(name = "distCodeCity",value = "市级行政区划代码 zbbl.xzqhdmCity"),
            @ApiImplicitParam(name = "distCodeCountry",value = "县级行政区划代码 zbbl.xzqhdmCountry"),
            @ApiImplicitParam(name = "distCode",value = "行政区划代码 zbbl.xzqhdm",required = true),
            @ApiImplicitParam(name = "distName",value = "行政区划名称 zbbl.xzqhmc",required = true),
            @ApiImplicitParam(name = "inxStorageIAcotId",value = "入库id zbcktz.rkid"),
            @ApiImplicitParam(name = "buildLandAdd",value = "冻结-新增建设用地(BigDecimal) zbcktz.xzjsyd"),
            @ApiImplicitParam(name = "agclLand",value = "冻结-农用地(BigDecimal) zbcktz.nyd"),
            @ApiImplicitParam(name = "farmland",value = "冻结-耕地(BigDecimal) zbcktz.gd"),
            //@ApiImplicitParam(name = "inxOutStorageAcot.outStorageType",value = "出库类型 zbcktz.cklx",required = true),
            //@ApiImplicitParam(name = "inxOutStorageAcot.outStorageStatus",value = "出库状态 zbcktz.ckzt",required = true),
            @ApiImplicitParam(name = "remark",value = "备注 zbcktz.bz"),
    })
    @PostMapping(value = "/indexFree")
    @ResponseBody
    public String IndexStorageFreeze(@Valid IndexStorageFreezeModel indexStorageFreezeModal){
        String result = inxStorageAcotService.updateInxStorage(indexStorageFreezeModal);
        if("true".equals(result)) {
            return "Message:success";
        }
        return result;
    }


}
